package com.accesshollywood.GL;

import org.lwjgl.util.vector.Vector3f;

public class Keyframe implements Cloneable {
	public static final boolean	POLITE_KEYFRAME	= true;

	private Vector3f			pos;
	private Vector3f			rot;
	private Vector3f			scale;
	private float				alpha;					// range from 0.0f to
														// 1.0f
	private int					frames;

	public Keyframe() {
		pos = new Vector3f(0.0f, 0.0f, 0.0f);
		rot = new Vector3f(0.0f, 0.0f, 0.0f);
		scale = new Vector3f(1.0f, 1.0f, 1.0f);
		alpha = 1.0f;
		frames = 30;
	}

	public void setPosXYZ(Vector3f newPos) {
		pos = new Vector3f();
		setPosX(newPos.x);
		setPosY(newPos.y);
		setPosZ(newPos.z);
	}

	public void setPosX(float X) {
		pos.x = X;
	}

	public void setPosY(float Y) {
		pos.y = Y;
	}

	public void setPosZ(float Z) {
		pos.z = Z;
	}

	public void setRotXYZ(Vector3f newRot) {
		rot = new Vector3f();
		setRotX(newRot.x);
		setRotY(newRot.y);
		setRotZ(newRot.z);
	}

	public void setRotX(float X) { // pitch
		rot.x = X;
	}

	public void setRotY(float Y) { // heading
		rot.y = Y;
	}

	public void setRotZ(float Z) { // bank
		rot.z = Z;
	}

	public void setScaleXYZ(Vector3f newScale) {
		scale = new Vector3f();
		setScaleX(newScale.x);
		setScaleY(newScale.y);
		setScaleZ(newScale.z);
	}

	public void setScaleX(float X) { // pitch
		scale.x = X;
	}

	public void setScaleY(float Y) { // heading
		scale.y = Y;
	}

	public void setScaleZ(float Z) { // bank
		scale.z = Z;
	}

	public void setFrames(int newFrames) {
		this.frames = newFrames;
	}

	public void setAlpha(float newAlpha) {
		this.alpha = newAlpha;
	}

	public Vector3f getPosXYZ() {
		return pos;
	}

	public float getPosX() {
		return (pos == null) ? null : pos.x;
	}

	public float getPosY() {
		return (pos == null) ? null : pos.y;
	}

	public float getPosZ() {
		return (pos == null) ? null : pos.z;
	}

	public Vector3f getRotXYZ() {
		return rot;
	}

	public float getRotX() {
		return (rot == null) ? null : rot.x;
	}

	public float getRotY() {
		return (rot == null) ? null : rot.y;
	}

	public float getRotZ() {
		return (rot == null) ? null : rot.z;
	}

	public Vector3f getScaleXYZ() {
		return scale;
	}

	public float getScaleX() {
		return (scale == null) ? null : scale.x;
	}

	public float getScaleY() {
		return (scale == null) ? null : scale.y;
	}

	public float getScaleZ() {
		return (scale == null) ? null : scale.z;
	}

	public float getAlpha() {
		return alpha;
	}

	public float getFrames() {
		return frames * 1000 / 30.0f; // this gives us millisecond resolution
										// for smoother playback
	}

	public Keyframe clone() {
		Keyframe newKey = new Keyframe();
		newKey.pos.x = pos.x;
		newKey.pos.y = pos.y;
		newKey.pos.z = pos.z;
		newKey.rot.x = rot.x;
		newKey.rot.y = rot.y;
		newKey.rot.z = rot.z;
		newKey.scale.x = scale.x;
		newKey.scale.y = scale.y;
		newKey.scale.z = scale.z;
		newKey.alpha = alpha;
		newKey.frames = frames;
		
		return newKey;
	}
}
